package peration;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddBook implements IOperation {

    @Override
    public void dowork(BookList bookList) {
        System.out.println("请输入你要新增的图书");
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        int cur = bookList.getUsedSize();
        int t = 0;
        for (int i = 0; i < cur; i++) {
            Book book = bookList.getBook(i);
            if (name.equals(book.getName())) {
                System.out.println("已有" + name + "这本书");
                t = 1;
                break;
            }
        }
        if(t==0){
            System.out.println("请输入"+ name + "这本书的作者");
            String author = sc.nextLine();
            System.out.println("请输入" + name + "这本书的价格");
            String price = sc.nextLine();
            System.out.println("请输入" + name + "这本书的类型");
            String type = sc.nextLine();
            Book book = new Book(name, author, price , type);
            bookList.setBook(book);
            bookList.setUsedSize(bookList.getUsedSize()+1);
            System.out.println("添加成功");


        }

    }
}
